package com.dai.zhenfujin.my.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.DisplayMetrics;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.dai.zhenfujin.Constants.Constants;
import com.dai.zhenfujin.R;
import com.dai.zhenfujin.base.BaseActivity;

//用户协议
public class AboutAgreementActivity extends BaseActivity {

    private WebView webView;
    private TextView tv_version, title_textview;
    private FrameLayout fl_img;
    private int type;
    private String url;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about_agreement_activity);
        initView();
    }

    private void initView() {
        type = getIntent().getIntExtra("type", 0);
        webView = findViewById(R.id.webview);
        title_textview = findViewById(R.id.title_textview);
        fl_img = findViewById(R.id.fl_img);
        if (type == 0) {
            title_textview.setText("用户协议");
        } else if (type == 1) {
            title_textview.setText("隐私协议");
        } else {
            title_textview.setText("平台规则");
        }

        fl_img.setOnClickListener(v -> finish());
        getAgreement();
    }

    private void getAgreement() {
        WebSettings webSettings = webView.getSettings();
        webSettings.setSupportZoom(true);
        //设置是否支持缩放
        // 设置显示缩放按钮
        webSettings.setBuiltInZoomControls(true);
        //隐藏webview缩放按钮
        webSettings.setDisplayZoomControls(false);
        //设置WebView是否允许执行JavaScript脚本，默认false，不允许
        webSettings.setJavaScriptEnabled(true);
        //设置自适应屏幕宽度 设置webview推荐使用的窗口
        webSettings.setUseWideViewPort(true);


        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);
        int mDensity = metrics.densityDpi;
       /* if (mDensity == 240) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else if (mDensity == 160) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
        } else if (mDensity == 120) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.CLOSE);
        } else if (mDensity == DisplayMetrics.DENSITY_XHIGH) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else if (mDensity == DisplayMetrics.DENSITY_TV) {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.FAR);
        } else {
            webSettings.setDefaultZoom(WebSettings.ZoomDensity.MEDIUM);
        }*/
        //LayoutAlgorithm.SINGLE_C内容将自动缩放OLUMN:适应屏幕，
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        if (type == 0) {
            url = Constants.HOST + "system/getAgreement.php?art_id=10001";
        } else if (type == 1) {
            url = Constants.HOST + "system/getAgreement.php?art_id=10003";
        } else {
            url = Constants.HOST + "system/getAgreement.php?art_id=10004";
        }

        webView.loadUrl(url);
      /*  Map<String, Object> params = new HashMap<>();
        Map<String, String> params2 = new HashMap<>();
        params2.put("user_id","");
        params.put("req_bd",  params2);

        HttpClient.post(this, Constants.AGREEMENT + "?art_id=10001", params, new CallBack<UserBean>() {
            @Override
            public void onSuccess(UserBean resultBean) {



            }
        });*/
    }
}
